--[[
    NuckPluck - An android game for learning the Thai alphabet
    Copyright (C) 2013 Nathan Kieffer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    Contact: nathankieffer@gmail.com
--]]

local Cloud = {}

function Cloud.newCloud(parent, num)
   local cloud = display.newImage(parent,string.format("images/clouds%d.png", num))
   print(cloud)
   cloud.anchorX = 0
   cloud.anchorY = 0
   cloud.x = math.random(display.contentWidth)
   cloud.y = math.random(display.contentHeight)
   cloud.alpha = math.random(5,10) * 0.1
   cloud.speed = math.random(5)
   local scale = math.random(5,10) * 0.1
   cloud.xScale = scale
   cloud.yScale = scale
   function cloud:enterFrame(event)
      if cloud.x > display.contentWidth then
	 cloud.x = -cloud.width
	 cloud.y = math.random(display.contentHeight)
	 cloud.alpha = math.random(5,8) * 0.1
	 cloud.speed = math.random(5)
	 local scale = math.random(5,10) * 0.1
	 cloud.xScale = scale
	 cloud.yScale = scale
      end
      
      cloud.x = cloud.x + cloud.speed
      cloud.y = cloud.y + (math.random(-1,1) * math.random())
   end
   Runtime:addEventListener("enterFrame", cloud)
   return cloud
end
return Cloud
   